import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
   'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Y33S4B736QGaNYmfKCR\n' +
'sY2LRvxBOiqMs/PyfdPqFBzrJGiutf3UOdU49TmBvNWOwp/YTnDIx+9vHuPWK6wx\n' +
'WlSAUsiVd1rMow4EN145d51uTmAn2zWDQx/fNiADR0GwCNfjKr11DilRJboBABLP\n' +
'0t3+Z84/bSxsLVhn4FnKQ8AxQDQ3/SfhmPTGRr+Eor0hqkii/eVzstXX1p9ajJxB\n' +
'7H8r3cShrp86ZeNlCbkvFVbU2ouyYh4/NUdD3x6nHNZ0gTcR95CvfjqhpbJtUALM\n' +
'9w8gQATfgSrL3c0002PrymGUPGmh7MZ2DX+8V1PDjP8xnUmvJapqcGrmLs3GG0vx\n' +
'NQIDAQAB';

const privateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRjfdLgHvfpAZo\n' +
'1iZ8oJGxjYtG/EE6Koyz8/J90+oUHOskaK61/dQ51Tj1OYG81Y7Cn9hOcMjH728e\n' +
'49YrrDFaVIBSyJV3WsyjDgQ3Xjl3nW5OYCfbNYNDH982IANHQbAI1+MqvXUOKVEl\n' +
'ugEAEs/S3f5nzj9tLGwtWGfgWcpDwDFANDf9J+GY9MZGv4SivSGqSKL95XOy1dfW\n' +
'n1qMnEHsfyvdxKGunzpl42UJuS8VVtTai7JiHj81R0PfHqcc1nSBNxH3kK9+OqGl\n' +
'sm1QAsz3DyBABN+BKsvdzTTTY+vKYZQ8aaHsxnYNf7xXU8OM/zGdSa8lqmpwauYu\n' +
'zcYbS/E1AgMBAAECggEAKRDEFISyQcpYAzVsR2IECyJs19VZRvfNqPo2XBgqOBTO\n' +
's8zb6Ag9DbROPCgv13yWRGeksQKDJkMyqIAHmXleFpCWsSJjwAcIMS/u/Za2dk1g\n' +
'r3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GsF92j708Q/SYANdCeCYMSlIH8xXMl1fgK3O\n' +
'YSPbtf4kSvS8644cHSmmcB3ouQBlET1wRTxxBtsR2ekU16epuVcKblCrCj2LSAbQ\n' +
's/HEA/CbKv4K2Ix6o8fjjcTM';

// 加密
export function encrypt(txt: string) {
    const encryptor = new JSEncrypt();
    encryptor.setPublicKey(publicKey); // 设置公钥
    return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt: string) {
    const encryptor = new JSEncrypt();
    encryptor.setPrivateKey(privateKey); // 设置私钥
    return encryptor.decrypt(txt); // 对数据进行解密
}
